from sqlalchemy.orm import Session

from api.model.llm_factory_model import LLMFactoryModel
from api.utils.session import with_session
from api.vo.value.llm_factory import LLMFactoryValue


@with_session
def list_factory(session: Session):
    data = (session.query(LLMFactoryModel.name, LLMFactoryModel.logo, LLMFactoryModel.tags, LLMFactoryModel.key)
            .filter(LLMFactoryModel.logo != None)
            .filter(LLMFactoryModel.status == "1")
            .filter(LLMFactoryModel.logo != "").all())
    list = [LLMFactoryValue(name=el.name, logo=el.logo, tags=el.tags, key=el.key) for el in data]
    return list

@with_session
def get_factory(session: Session, name: str):
    el = session.get(LLMFactoryModel, name)
    return LLMFactoryValue(name=el.name, logo=el.logo, tags=el.tags, key=el.key)